import java.net.*;
import java.io.*;

/**
 * This class is the heart of the server. It connects
 * to the client it gets from the socket. The input from
 * the client is passed to the parser
 * @author Marco Vellinga
 * @author Sander Wagenaar
 *
 */
public class Server implements Runnable {
	
	// Variable
	Socket client;
	
			/**
			 * Constructor
			 * @param client
			 * @throws IOException
			 */
			public Server(Socket client) throws IOException{
				// Set the socked the server is connected too.
				this.client = client;
			}
			
			/**
			 * The main function of the server. This function gets
			 * the file from the input stream, passes it to the parser
			 * After parsing we use the data to put it in the database
			 */
			@Override
			public void run() {
				
				try{
				
					while(true){
					// Set inputstream to listen too
					InputStream in = client.getInputStream();
					SAXparser parser = new SAXparser(in);
					
					try {
						new ConnectDb(parser.getData());	
					} catch (InstantiationException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
					
				}catch (IOException ioe){
					System.err.println(ioe);
				}
			}
}

